#pragma once

#include <vector>

namespace solution_055
{

class Solution
{
public:
    bool canJump(std::vector<int>& nums)
    {
        /* stack bottom */
        int sb = nums.size();
        for (int i = (int)nums.size() - 2; i >= 0; --i) {
            if (nums.at(i) == 0) {
                nums.at(--sb) = i;
            } else {
                while ((int)nums.size() > sb && i + nums.at(i) > nums.back())
                    nums.pop_back();
            }
        }
        return sb == (int)nums.size();
    }
};

}  /* namespace solution_055 */
